package com.mercury.ec.module.air.controller.admin.order.vo.order;

import com.mercury.ec.framework.common.enums.DeliveryTypeEnum;
import com.mercury.ec.framework.common.validation.InEnum;
import com.mercury.ec.module.air.controller.admin.order.validator.AirOrderCreateSequenceProvider;
import com.mercury.ec.module.air.validator.AirGroup;
import com.mercury.ec.module.air.controller.admin.order.vo.orderpassenger.AirOrderPassengerCreateReqVO;
import com.mercury.ec.module.air.controller.admin.order.vo.orderprice.AirOrderPriceCreateReqVO;
import com.mercury.ec.module.air.controller.admin.order.vo.orderroute.AirOrderRouteCreateReqVO;
import com.mercury.ec.module.air.enums.*;
import com.mercury.ec.module.basic.enums.BasicBizScopeTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.group.GroupSequenceProvider;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Data
@GroupSequenceProvider(value = AirOrderCreateSequenceProvider.class)
@Schema(description = "管理后台 - 机票订单新增 Request VO")
public class AirOrderCreateReqVO {

    @Schema(description = "订单来源 字典（air_order_source_type 1-手工订单/2-白屏/3-ETERM/4-需求单）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @NotNull(message = "订单来源不能为空")
    @InEnum(value = AirOrderSourceTypeEnum.class, message = "订单来源必需是【1-手工订单/2-白屏/3-ETERM/4-需求单/5-分销】")
    private Integer sourceType;

    @Schema(description = "来源单号")
    @Length(max = 64, message = "来源单号长度不能超过64")
    private String sourceNo;

    @Schema(description = "查询渠道编号（白屏来源订单必填）", requiredMode = Schema.RequiredMode.REQUIRED, example = "102")
    @NotNull(message = "查询渠道编号不能为空", groups = {AirGroup.WhiteScreen.class})
    private Long channelId;

    @Schema(description = "预订渠道编号", example = "102")
    private Long bookChannelId;

    @Schema(description = "预订渠道id", example = "11231313")
    private String bookingKey;

    @Schema(description = "预定参数加密串（白屏来源订单必填）", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
    @NotNull(message = "预定参数加密串不能为空", groups = {AirGroup.WhiteScreen.class})
    private String bookingSecret;

    @Schema(description = "是否占座（销售、改签单必填）", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    @NotNull(message = "是否占座不能为空", groups = {AirGroup.Sale.class, AirGroup.Change.class})
    private Boolean occupySeat;

    @Schema(description = "最后改签类型（改签单必填） 字典（air_order_change_type 1-改期/2-升舱）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @InEnum(value = AirOrderChangeTypeEnum.class, message = "最后改签类型必需是【1-改期/2-升舱】")
    @NotNull(message = "最后改签类型不能为空", groups = {AirGroup.Change.class})
    private Integer finallyChangeType;

//    @Schema(description = "原订单id")
//    private Long originOrderId;
//
//    @Schema(description = "原订单号")
//    @Length(max = 64, message = "原订单id长度不能超过64")
//    private String originOrderNo;


    @Schema(description = "系统客户端 字典（system_client_type 1-中台/2-分销/3-差旅）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @NotNull(message = "客户端不能为空")
    private Integer clientType;

    @Schema(description = "订单类型 字典（air_order_type 1-销售单/2-改签单/3-退票单/4-调账单）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @InEnum(value = AirOrderTypeEnum.class, message = "订单类型必需是【1-销售单/2-改签单/3-退票单/4-废票单/5-调账单】")
    @NotNull(message = "订单类型不能为空")
    private Integer type;

    @Schema(description = "团号")
    @Length(max = 32, message = "团号长度不能超过32")
    private String groupNo;

    @Schema(description = "业务类型 字典（basic_biz_scope_type 1-国内/2-国际）", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @InEnum(value = BasicBizScopeTypeEnum.class, message = "机票类型必需是【1-国内/2-国际】")
    @NotNull(message = "机票类型不能为空")
    private Integer scopeType;

    @Schema(description = "行程类型 字典（air_order_route_type 1-单程/2-往返/3-联程）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @InEnum(value = AirOrderRouteTypeEnum.class, message = "行程类型必需是【1-单程/2-往返/3-联程】")
    @NotNull(message = "行程类型不能为空")
    private Integer routeType;

    @Schema(description = "订座编码")
    @Length(max = 16, message = "订座编码长度不能超过16")
    private String pnr;

    @Schema(description = "编码状态 HK-预订/XX-取消/RR-出票")
    @Length(max = 8, message = "编码状态长度不能超过8")
    private String pnrStatus;

    @Schema(description = "PNR内容")
    private String pnrContent;

    @Schema(description = "航司大编码")
    @Length(max = 16, message = "航司大编码长度不能超过16")
    private String bigPnr;

    @Schema(description = "客户id 见表（basic_customer.id）", requiredMode = Schema.RequiredMode.REQUIRED, example = "16640")
    @NotNull(message = "客户不能为空")
    private Long customerId;

    @Schema(description = "客户协议类型 字典（air_customer_agreement_type 1-普通/2-GP/3-三方协议）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @NotNull(message = "客户协议类型不能为空")
    private Integer customerAgreementType;

    @Schema(description = "客户协议号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
    @NotNull(message = "客户协议号不能为空（三方协议必填）", groups = {AirGroup.CustomerAgreement.class})
    @Length(max = 64, message = "客户协议号长度不能超过64")
    private String customerAgreementNo;

    @Schema(description = "业务员id 见表（system_users.id）", requiredMode = Schema.RequiredMode.REQUIRED, example = "14732")
    @NotNull(message = "业务员id不能为空")
    private Long salesmanUserId;

    @Schema(description = "预订员id 见表（system_users.id）", requiredMode = Schema.RequiredMode.REQUIRED, example = "14732")
    @NotNull(message = "预订员id不能为空")
    private Long bookUserId;

    @Schema(description = "预订时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "预订时间不能为空")
    private LocalDateTime bookTime;

    @Schema(description = "预订office")
    @Length(max = 16, message = "预订office长度不能超过16")
    private String bookOffice;

    @Schema(description = "是否需要发票（销售、改签单必填）", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "是否需要发票不能为空", groups = {AirGroup.Sale.class, AirGroup.Change.class})
    private Boolean needInvoice;

    @Schema(description = "开票方式（需发发票必填） 字典（basic_make_invoice_type 1-统一发票/2-单项发票）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @NotNull(message = "开票方式不能为空", groups = {AirGroup.NeedInvoice.class})
    private Integer makeInvoiceType;

    @Schema(description = "是否回收发票（退票单必填）", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    @NotNull(message = "是否回收发票不能为空", groups = {AirGroup.Return.class})
    private Boolean recycleInvoice;

    @Schema(description = "发票类型（需要发票必填） 字典（basic_air_invoice_type）", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @NotNull(message = "发票类型不能为空", groups = {AirGroup.NeedInvoice.class, AirGroup.NeedRecycleInvoice.class})
    private Integer invoiceType;

    @Schema(description = "配送方式（需要发票必填） 字典（system_delivery_type）", example = "1")
    @InEnum(value = DeliveryTypeEnum.class, message = "配送方式必需是【1--送票上门/2-邮寄发票/3-自取/4-邮箱】")
    @NotNull(message = "配送方式不能为空", groups = {AirGroup.NeedInvoice.class, AirGroup.NeedRecycleInvoice.class})
    private Integer deliveryType;

    @Schema(description = "配送备注", example = "你猜")
    @Length(max = 255, message = "配送备注长度不能超过255")
    private String deliveryRemark;

    @Schema(description = "配送费（需要发票必填）", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "配送费不能为空", groups = {AirGroup.NeedInvoice.class, AirGroup.NeedRecycleInvoice.class})
    private BigDecimal deliveryFee;

    @Schema(description = "配送联系人")
    @Length(max = 64, message = "配送联系人长度不能超过64")
    private String deliveryContact;

    @Schema(description = "配送联系人电话")
    @Length(max = 16, message = "配送联系人电话长度不能超过16")
    private String deliveryContactPhone;

    @Schema(description = "配送城市id")
    private Long deliveryCityId;

    @Schema(description = "配送地址")
    @Length(max = 255, message = "配送联系人地址长度不能超过255")
    private String deliveryAddress;

    @Schema(description = "配送邮箱")
    @Length(max = 128, message = "配送联系人地址长度不能超过128")
    private String deliveryEmail;

    @Schema(description = "配送员id 见表（system_users.id）", example = "14732")
    private Long deliveryUserId;

    @Schema(description = "配送时间")
    private LocalDateTime deliveryTime;

    @Schema(description = "最后退票订单类型（退票单必填） 字典（air_order_return_order_type 1-退票/2-废票）", example = "1")
    @InEnum(value = AirOrderReturnOrderTypeEnum.class, message = "最后退票订单类型必需是【1-退票/2-废票】")
    @NotNull(message = "最后退票类型不能为空", groups = {AirGroup.Return.class})
    private Integer finallyReturnOrderType;

    @Schema(description = "最后退票类型（退票单必填） 字典（air_order_return_type 1-自愿/2-非自愿）", example = "1")
    @InEnum(value = AirOrderReturnTypeEnum.class, message = "最后退票类型必需是【1-自愿/2-非自愿】")
    @NotNull(message = "最后退票类型不能为空", groups = {AirGroup.Return.class})
    private Integer finallyReturnType;

    @Schema(description = "最后退票原因（退票单非自愿必填） 字典（air_order_return_cause）", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotNull(message = "最后退票原因不能为空", groups = {AirGroup.Return.class, AirGroup.UnWillReturn.class})
    private Integer finallyReturnCause;

    @Schema(description = "最后调账类型（调账单必填） 字典（air_order_adjust_type 1-/2-/3-）", example = "2")
    @InEnum(value = AirOrderAdjustTypeEnum.class, message = "最后调账类型必需是【1-/2-/3-】")
    @NotNull(message = "最后调账类型不能为空", groups = {AirGroup.Adjust.class})
    private Integer finallyAdjustType;

//    @Schema(description = "支付方式id 见表（basic_pay_type.id）", example = "15844")
//    @NotNull(message = "支付方式不能为空")
//    private Long salePayTypeId;

    @Schema(description = "支付科目id 见表（basic_pay_subject.id）", example = "27542")
    @NotNull(message = "支付科目不能为空")
    private Long salePaySubjectId;

    @Schema(description = "支付账号", example = "20047")
    @Length(max = 64, message = "支付账号长度不能超过64")
    private String salePayAccount;

    @Schema(description = "支付单号")
    @Length(max = 64, message = "支付单号长度不能超过64")
    private String salePayOrderNo;

    @Schema(description = "支付时间")
    private LocalDateTime salePayTime;

    @Schema(description = "是否在线支付")
    private Boolean salePayOnline;

    @Schema(description = "采购商id 见表（basic_vendor.id）", example = "28311")
    private Long purchaseId;

    @Schema(description = "采购单号")
    @Length(max = 64, message = "采购单号长度不能超过64")
    private String purchaseOrderNo;

    @Schema(description = "采购支付科目id 见表（basic_pay_subject.id）", example = "22116")
    private Long purchasePaySubjectId;

    @Schema(description = "采购支付方式id 见表（basic_pay_type.id）", example = "8940")
    private Long purchasePayTypeId;

    @Schema(description = "采购支付账号", example = "4194")
    @Length(max = 64, message = "采购支付账号长度不能超过64")
    private String purchasePayAccount;

    @Schema(description = "采购支付单号")
    @Length(max = 64, message = "采购支付单号长度不能超过64")
    private String purchasePayOrderNo;

    @Schema(description = "采购支付时间")
    private LocalDateTime purchasePayTime;

    @Schema(description = "采购是否在线支付")
    private Boolean purchasePayOnline;

    @Schema(description = "联系人")
    @Length(max = 64, message = "联系人长度不能超过64")
    private String contact;

    @Schema(description = "联系人证件类型 字典（system_card_type）", example = "1")
    private Integer contactCardType;

    @Schema(description = "联系人证件号")
    @Length(max = 32, message = "联系人证件号长度不能超过32")
    private String contactCardNo;

    @Schema(description = "联系人电话")
    @Length(max = 16, message = "联系人电话长度不能超过16")
    private String contactPhone;

    @Schema(description = "联系人手机")
    @Length(max = 16, message = "联系人手机长度不能超过16")
    private String contactMobile;

    @Schema(description = "联系人邮箱")
    @Length(max = 128, message = "联系人邮箱长度不能超过128")
    private String contactEmail;

    @Schema(description = "备注", example = "你说的对")
    @Length(max = 255, message = "备注长度不能超过255")
    private String remark;

    @Valid
    @Schema(description = "行程信息", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "行程信息不能为空")
    private List<AirOrderRouteCreateReqVO> routes;

    @Valid
    @Schema(description = "乘客信息", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "乘客信息不能为空")
    private List<AirOrderPassengerCreateReqVO> passengers;

    @Valid
    @Schema(description = "价格信息", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "价格信息不能为空")
    private List<AirOrderPriceCreateReqVO> prices;
}
